const _ = require("lodash");

// 常规解法
(function () {
    let a, b, c;
    new Promise((resolve => {
        setTimeout(() => {
            a = 'hello';
            resolve()
        }, 10)
    })).then(() => {
        return new Promise((resolve) => {
            setTimeout(() => {
                b = 'lagou';
                resolve()
            }, 10)
        })
    }).then(() => {
        return new Promise((resolve => {
            setTimeout(() => {
                c = 'I ❤ U';
                console.log(a + b + c);
            }, 10)
        }))
    })
})();

// 更简洁一些的解法
(function () {
    let a, b, c;
    function helper(time, callback) {
        return new Promise((resolve => {
            setTimeout(() => {
                callback();
                resolve();
            }, time);
        }))
    }
    const buildPromiseWithTime10 = _.curry(helper)(10);
    let p1 = buildPromiseWithTime10(() => {
        a = 'hello';
    });

    let p2 = buildPromiseWithTime10(() => {
        b = 'lagou';
    });

    let p3 = buildPromiseWithTime10(() => {
        c = 'I ❤ U';
        console.log(a + b + c);
    });
    p1.then(p2).then(p3);
})();





